#include <compilation/Program.h>


extern FILE *yyin;
extern int yyparse();
extern int yydebug;

extern compilation::Program::ParseContext parseContext;


int main(int argc, char** argv)
{
  // yydebug = 1;
  compilation::Program program;
  parseContext.setProgram(program);

  if (argc < 2)
  {
    std::cerr << "usage: " << argv[0] << " <file.c>\n";
    return 1;
  }

  std::string inputFile = argv[1];
  yyin = std::fopen(inputFile.c_str(), "r");

  while (yyparse() != 0);

  if (yyin) std::fclose(yyin);
  std::cout << std::endl;

  program.setScopes();
  program.computeDominators();
  program.computeDominationFrontiers();
  program.insertPhiFunctions();
  program.renameSSA();

  program.exportToDot(inputFile + ".cfg");

  return 0;
}
